package com.jhws.core.shiro.realms;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.util.ByteSource;

public class AppRealm extends AuthorizingRealm {
        @Override
        public boolean supports(AuthenticationToken token) {
            if("AppAuthToken".equals(token.getClass().getSimpleName()))
                return true;
            return false;
        }

        @Override
        protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
            String username = (String)token.getPrincipal();
            return new SimpleAuthenticationInfo(username, //用户名
                    "none", //密码
                    ByteSource.Util.bytes("hehe"),//salt=username+salt
                    getName() );
        }

        @Override
        protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
            return null;
        }


}

